package web.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @description
 * @className ServerDemo
 * @package web.tcp
 * @author dongww@hsyuntai.com
 * @date 2020/3/11 14:03
 * @copyright 版权归 HSYUNTAI 所有
 */
public class ServerDemo {

    public static void main(String[] args) throws IOException {
        // 在端口上创建一个服务器套接字
        ServerSocket serverSocket = new ServerSocket(999);

        // 监听来自客户端的连接
        Socket socket = serverSocket.accept();

        InputStream inputStream = socket.getInputStream();

        byte[] bytes = new byte[1024];
        int len = inputStream.read(bytes);

        System.out.println(new String(bytes,0,len));
    }
}